package utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.Reader;

/**
 * Created by jianweilin on 16/8/28.
 */
public class MybatisUtil {
    private static SqlSessionFactory sqlSessionFactory = null;
    private final static String LOCAL_JDBC = "jdbc/mybatis-conf.xml";
    static {
        System.out.println("====INIT Mybatis BEGIN ====");
        Reader rdr;
        try {
            rdr = Resources.getResourceAsReader(LOCAL_JDBC);
            sqlSessionFactory = new SqlSessionFactoryBuilder().build(rdr);
            rdr.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("====INIT Mybatis END ====");
    }

    public static SqlSessionFactory getSqlSessionFactory(){
        return sqlSessionFactory;
    }
}
